
package TimeToWork.Android;


import TimeToWork.Android.WeekFragmentAdapter.Direction;
import TimeToWork.Android.WeekFragmentAdapter.Page;

import android.os.Bundle;
import android.support.v4.view.ViewPager;

import com.viewpagerindicator.TitlePageIndicator;

public class DayViewActivity extends BaseSampleActivity {

    private static final String TAG = "DayViewActivity";

    private DataStorageInterface mDataStorageInterface;

    private WeekFragmentAdapter.Page mFocusPage = Page.MIDDLE;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        
        
        setContentView(R.layout.simple_titles);

        

        mPager = (ViewPager)findViewById(R.id.pager);
        
        mAdapter = new WeekFragmentAdapter(getSupportFragmentManager(), ((TimeToWork)this.getApplicationContext()).getDataStorageInterface(), mPager);
        mPager.setAdapter(mAdapter);

        mIndicator = (TitlePageIndicator)findViewById(R.id.indicator);
        mIndicator.setViewPager(mPager);
        mIndicator.setCurrentItem(Page.MIDDLE.ordinal());

        mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            public void onPageSelected(int position) {
                mFocusPage = WeekFragmentAdapter.Page.values()[position];
            }

            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            public void onPageScrollStateChanged(int state) {
                if (state == ViewPager.SCROLL_STATE_IDLE) {

                    if (mFocusPage == Page.LEFT) {
                        mAdapter.move(Direction.RIGHT);
                        //TODO: Skapa en ny metod i mAdapter som skiftar DCWeek

                        mAdapter.offset--;
                        //TextView foo = (TextView)mPager.getChildAt(PAGE_MIDDLE).findViewById(
                        //        R.id.textView1);
                        //foo.setText("Week: " + mAdapter.getWeek(PAGE_MIDDLE) + frag.getText());
                        //foo = (TextView)mPager.getChildAt(PAGE_LEFT).findViewById(R.id.textView1);
                        //foo.setText("Week: " + mAdapter.getWeek(PAGE_LEFT));
                    } else if (mFocusPage == Page.RIGHT) {
                        mAdapter.move(Direction.LEFT);
                        mAdapter.offset++;
                        /*
                        TextView foo = (TextView)mPager.getChildAt(PAGE_MIDDLE).findViewById(
                                R.id.textView1);
                        foo.setText("Week: " + mAdapter.getWeek(PAGE_MIDDLE));
                        foo = (TextView)mPager.getChildAt(PAGE_RIGHT).findViewById(R.id.textView1);
                        foo.setText("Week: " + mAdapter.getWeek(PAGE_RIGHT));
                        */
                    }

                    mPager.setCurrentItem(Page.MIDDLE.ordinal(), false);
                }
            }
        });
    }
}
